<?php

require_once('publiccontroller.php');

// Sert à afficher les posts
class News extends PublicController
{
	function News()
	{
		parent::PublicController();
		$this->set_page_title('Actualités');
		$this->load->model('Post');
	}

	function show($id, $page = 1)
	{
		// actualité demandée
		$data['post'] = $this->Post->get_by_id($id);
		$data['post_tags'] = $this->Post->tags($id);
		// liste des actualités
		$page = intval($page) > 0 ? $page : 1;
		$data['posts'] = $this->Post->get_page($page);
		$data['page'] = $page;
		$data['nb_pages'] = $this->Post->get_nb_pages();
		$data['tag_cloud'] = $this->Post->tag_cloud();
		$this->_display('show', $data);
	}

	function tagged($tag_id)
	{
		$data['posts'] = $this->Post->get_by_tag($tag_id);
		$this->_display('result', $data);
	}

	// idem que show, mais sans le layout
	/*function get($id)
	{
		$data['post'] = $this->Post->get_by_id($id);
		$data['post_tags'] = $this->Post->tags($id);
		$this->_raw_display('news/_news_content', $data);
	}*/

	function get_titles($page = 1)
	{
		$data['posts'] = $this->Post->get_page($page);
		$data['page'] = $page;
		$data['nb_pages'] = $this->Post->get_nb_pages();
		$this->_raw_display('news/_news_titles', $data);
	}
}
